extends Node
class_name State_Machine

signal transitioned(state_name)

export var initial_state:=NodePath()
onready var state: State = get_node(initial_state)


func _ready():
	yield(owner,"ready")
	
	for child in get_children():
		child.state_machine = self
	state.enter()
	
func _unhandled_input(_event:InputEvent):
	state.handle_input(_event)
	
func _process(_delta):

	state.update()
	
func transition_to(target_state_name:String):
	if not has_node(target_state_name):
		return
	
	state.exit()
	state = get_node(target_state_name)
	state.enter()
	emit_signal("transitioned",state.name)
